let kLoginSuccessEventName = 'kLoginSuccessEventName'    //登录成功的通知
let KModifyInfoSuccess ="KModifyInfoSuccess"//修改信息成功
let KButtonLoadingSuccess ="KServiceLoadingSuccess"//按钮loading 消失
let KPolicySaveSuccess = "KPolicySaveSuccess"//取关政策 保存政策触发
let KUpdateJobList = 'KUpdateJobList' //提交收藏，提交投递更新列表
let KExtraInfoSuccess ='KExtraInfoSuccess' //修改附加信息成功
let KUploadFileProgress = 'KUploadFileProgress'//返回上传图片进度
let KUploadFileSuccess = 'KUploadFileSuccess'//返回上传图片成功
let KExtraDescribeSuccess = 'KExtraDescribeSuccess' //编辑职位描述成功
let KLocationSuccess = 'KLocationSuccess' //定位成功
let KEntInfoSuccess = 'KEntInfoSuccess' //修改企业基本信息
let KChoosePositonSuccess = 'KChoosePositonSuccess' //选择3级职位成功
let KJobFairSuccess = 'KJobFairSuccess' //招聘会报名成功
let KCancelInvitationSuccess = 'KCancelInvitationSuccess' //取消面试邀请成功
let KVideoInvitation = 'KVideoInvitation' //视频面试返回标志
let KEvaluateSuccess = 'KEvaluateSuccess'//评价完毕返回
let KLoginOutSuccess = 'KLoginOutSucess'//注销用户成功
let KRegisterSuccess = 'KRegisterSuccess'//企业注册成功
let KOrgRegisterSuccess = 'KOrgRegisterSuccess' // 培训机构注册成功
let GraduatesLocal = 'graduatesLocal' // 获取工作地区
let IntentSetting = 'IntentSetting' // 获取设置
// let TabBarRedDot = 'TabBarRedDot' // 我的消息

var events = {};

function on(name, self, callback) {
    console.log(events)
    var tuple = [self, callback];
    var callbacks = [];
        callbacks = events[name];
    if (Array.isArray(callbacks)) {
        callbacks.splice(name,1)
        callbacks.push(tuple);
    }
    else {
        events[name] = [tuple];
    }
  
}

function remove(name, self) {
    var callbacks = events[name];
    if (Array.isArray(callbacks)) {
        events[name] = callbacks.filter((tuple) => {
            return tuple[0] != self;
        })
    }

}

function emit(name, data) {
  console.log('被调用', name, data)
    var callbacks = events[name];
    if (Array.isArray(callbacks)) {
        callbacks.map((tuple) => {
            var self = tuple[0];
            var callback = tuple[1];
            callback.call(self, data);
        })
    }
}


exports.on = on;
exports.remove = remove;
exports.emit = emit;
exports.kLoginSuccessEventName = kLoginSuccessEventName;
exports.KModifyInfoSuccess = KModifyInfoSuccess;
exports.KButtonLoadingSuccess = KButtonLoadingSuccess;
exports.KPolicySaveSuccess = KPolicySaveSuccess;
exports.KUpdateJobList = KUpdateJobList;
exports.KExtraInfoSuccess = KExtraInfoSuccess;
exports.KUploadFileProgress = KUploadFileProgress;
exports.KUploadFileSuccess = KUploadFileSuccess;
exports.KExtraDescribeSuccess = KExtraDescribeSuccess;
exports.KLocationSuccess = KLocationSuccess;
exports.KEntInfoSuccess = KEntInfoSuccess;
exports.KChoosePositonSuccess = KChoosePositonSuccess;
exports.KJobFairSuccess = KJobFairSuccess;
exports.KCancelInvitationSuccess = KCancelInvitationSuccess;
exports.KVideoInvitation = KVideoInvitation;
exports.KEvaluateSuccess = KEvaluateSuccess;
exports.KLoginOutSuccess = KLoginOutSuccess;
exports.KRegisterSuccess = KRegisterSuccess;
exports.KOrgRegisterSuccess = KOrgRegisterSuccess
exports.GraduatesLocal = GraduatesLocal
exports.IntentSetting = IntentSetting
// exports.TabBarRedDot = TabBarRedDot